/***********************************************************************************/
/* Code license:  GNU General Public License v3                                    */
/* Main page:     https://code.google.com/p/library-cross-platform/                */
/* Issue tracker: https://code.google.com/p/library-cross-platform/issues/list     */
/***********************************************************************************/

#ifndef __CPP_BITS_12_12_2012__
#define __CPP_BITS_12_12_2012__


#define BIT_SET(value,pos) ((value) | (1L << (pos)))
#define BIT_CLEAR(value,pos) ((value) & (~(1L << (pos))))
#define VALUE2BOOL(value) (value > 0 ? true : false)



/*************************************************************************
DESCRIPTION:
Returns the bit value from the data for defined position.

IN:
  data - input data, a bit value will be calculated from this value.
  pos  - which position will be used to calculate bit value.
         (position starts from 0(zero))
RETURN: return value of the bit.
*************************************************************************/
template <class type>
bool getBitValue(type data, int pos) {
  type value = (type)1;
  value = value << pos;
  return (value & data) ? true : false;
}

#endif /* __CPP_BITS_12_12_2012__ */
